<?php
/**
 * Created by PhpStorm.
 * User: 田家强
 * Date: 2017/3/20
 * Time: 17:09
 */

namespace Admin\Controller;


use Common\Controller\BaseController;
use Common\Model\BrandModel;

class BrandController extends BaseController
{
    /**
     * 首页模板展示
     */
    public function index()
    {
        $dataa = M('brand'); // 实例化User对象
        $count      = $dataa->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,1);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $Page->setConfig('header','共 %TOTAL_ROW% 条记录');
        $Page->setConfig('theme','%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
        $show       = $Page->show();// 分页显示输出
// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $data = $dataa->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('data',$data);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出



     $brand = m('brand')->select();
     $this->assign('brand',$brand);

        $this->display();
    }

    /**
     * 执行添加方法
     */
    public function add()
    {
        if(IS_POST)
        {
            $data = I('post.');
            //dump($data);
            $this->store(new BrandModel(),$data,u('admin/brand/index'));
        }
        $this->display();
    }

    public function edit()
    {
       $bid = I('get.bid');
       //dump($bid);
        if($_POST){
           $data = I('post.');
           $data['bid'] =$bid;
           $this->store(new BrandModel(),$data,u('admin/brand/index'));
        }
        $bids =  m('brand')->find($bid);
        //dump($bids);
        $this->assign('bids',$bids);
        $this->display();
    }

    /**
     * 删除方法
     */
    public function del()
    {
       $bid = I('get.bid');
       m('brand')->delete($bid);
       $this->success('删除成功',u('admin/brand/index'));

    }

    public function show()
    {

        $this->display();
    }
}